package com.tss.pojo;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;


public class Result implements Serializable{
	/**
	 * 响应结果
	 */
	private static final long serialVersionUID = 6554049783081782713L;


	//状态码
	private Integer status;
	
	//返回结果
	private Map<String, Object> result = new HashMap<String,Object>();
	
	//提示信息
	private String message;
	
	//跳转链接
	private String redirectUrl;
	
	// 状态码 正常
	public static final Integer STATUS_CODE_OK = 200;
	
	// 状态码 正常
	public static final Integer STATUS_CODE_EXISTENT = 201;
	
	// 状态码 正常
	public static final Integer STATUS_CODE_INEXISTENT = 202;

	// 状态码 无数据
	public static final Integer STATUS_CODE_NO_DATA = 300;

	// 状态码 参数格式错误
	public static final Integer STATUS_CODE_PARAMS_ERRORS = 400;

	// 状态码  没有权限
	public static final Integer STATUS_CODE_NO_PERMISSION = 403;

	// 状态码 数据异常
	public static final Integer STATUS_DATA_EXCEPTION = 401;

	// 状态码 未登录
	public static final Integer STATUS_NO_LOGIN = 402;

	// 状态码 服务器错误
	public static final Integer STATUS_CODE_SERVER_ERRORS = 500;

	// 错误信息 key
	public static final String ERRORS_MESSAGE_KEY = "errorsMessage";

	// 参数错误信息 key
	public static final String PARAMS_VAILD_FAIL = "paramsNotVaild";
		

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Map<String, Object> getResult() {
		return result;
	}

	public void setResult(Map<String, Object> result) {
		this.result = result;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getRedirectUrl() {
		return redirectUrl;
	}

	public void setRedirectUrl(String redirectUrl) {
		this.redirectUrl = redirectUrl;
	}
	
	public Result setSuccessMessage(String message){
		status=STATUS_CODE_OK;
		this.message = message;
		return this;
	}
	
	public Result setErrorMessage(String message){
		status = STATUS_CODE_SERVER_ERRORS;
		this.message = message;
		return this;
	}
	
	public void addResult(String key,Object value){
		result.put(key, value);
	}
	
	public String toString(){
		String string = JSONObject.fromObject(this).toString();
		return string;
	}
}
